package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.constant.MessageConstant;
import com.itheima.controller.dto.CheckGroupDto;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 检查组控制类
 * @Author makun
 * @Date 2023/9/13 14:22
 * @@Version 1.0
 */
@RestController
@RequestMapping("/checkGroup")
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;

    /**
     * 获取所有的检查组
     * @param queryString 查询条件
     * @return
     */
    @GetMapping("/all")
    public Result getAllCheckGroups(String queryString) {
        return Result.buildSuccess(checkGroupService.getAll(queryString));
    }

    /**
     * 新增一个检查组
     * @param checkGroupDto
     * @return
     */
    @PostMapping
    public Result save(@RequestBody CheckGroupDto checkGroupDto) {
        return checkGroupService.saveOne(checkGroupDto) ? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 分页查询检查组
     * @param queryPageBean
     * @return
     */
    @GetMapping
    public Result getCheckGroups(QueryPageBean queryPageBean) {
        return Result.buildSuccess(checkGroupService.findPage(queryPageBean));
    }
}
